﻿<UserControl x:Class="Big3.Hitbase.MainControls.MainPlaylistUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:misc="clr-namespace:Big3.Hitbase.Miscellaneous;assembly=Misc"
             xmlns:trans="clr-namespace:Transitionals;assembly=Transitionals"
             xmlns:transc="clr-namespace:Transitionals.Controls;assembly=Transitionals"
             xmlns:transt="clr-namespace:Transitionals.Transitions;assembly=Transitionals"
             xmlns:controls="clr-namespace:Big3.Hitbase.Controls;assembly=Controls"
             xmlns:dd="clr-namespace:Big3.Hitbase.Controls.DragDrop;assembly=Controls"
             xmlns:soundengine="clr-namespace:Big3.Hitbase.SoundEngine;assembly=SoundEngine"
             xmlns:sr="clr-namespace:Big3.Hitbase.SharedResources;assembly=Big3.Hitbase.SharedResources"
             mc:Ignorable="d" x:Name="PlaylistUserControl"
             d:DesignHeight="300" d:DesignWidth="300" Background="#50ffffff" 
             xmlns:my="clr-namespace:Big3.Hitbase.MainControls">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Controls;component/SplitButtonStyle.xaml" ></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" >


            </Style>


            <!--<Style TargetType="ListBoxItem" x:Key="MyItemContainerStyle">
                <Setter Property="Margin" Value="0"/>
                <Setter Property="Padding" Value="0"/>
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#20000000"></SolidColorBrush>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"></SolidColorBrush>
                </Style.Resources>
            </Style>-->

            <misc:LengthConverter x:Key="LengthConverter" />
            <misc:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

            <DataTemplate x:Key="PlaylistItemSingleTemplate">
                <Border x:Name="ItemBorder" BorderThickness="1" BorderBrush="Transparent" CornerRadius="2" Padding="0,2,0,2" TextElement.Foreground="{DynamicResource DefaultForeground}">
                    <Grid Name="ItemGrid">
                        <Grid.RenderTransform>
                            <TranslateTransform x:Name="ItemGridTranslate"  />
                        </Grid.RenderTransform>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <DockPanel x:Name="ItemDockPanel" Margin="0,0,5,0" ToolTip="{Binding Info.TitleAndArtist}">
                            <Image Grid.Column="1" Width="16" Height="16" Source="/Big3.Hitbase.SharedResources;component/Images/PlaylistError.png"
                                   Visibility="{Binding HasError, Converter={StaticResource BooleanToVisibilityConverter}}" 
                                   ToolTip="{Binding ErrorMessage}" />
                            <TextBlock Text="{Binding Path=Info.Title}" TextTrimming="CharacterEllipsis" ></TextBlock>
                            <TextBlock Foreground="Gray" TextTrimming="CharacterEllipsis" Text=" - " />
                            <TextBlock Foreground="Gray" TextTrimming="CharacterEllipsis" Text="{Binding Path=Info.Artist}" />
                        </DockPanel>
                        <TextBlock Grid.Column="1" Text="{Binding Path=Info.Length, Converter={StaticResource LengthConverter}}" />
                    </Grid>
                </Border>
                <DataTemplate.Triggers>
                    <Trigger SourceName="ItemBorder" Property="IsMouseOver" Value="True">
                        <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource MyListBoxItemHoverBackgroundBrush}" />
                        <Setter TargetName="ItemBorder" Property="BorderBrush" Value="#300000FF" />
                    </Trigger>
                    <DataTrigger Binding="{Binding Path=IsPlaying}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard  Name="PlayingStoryboard">
                                <Storyboard>
                                    <ThicknessAnimation Storyboard.TargetName="ItemGrid" Storyboard.TargetProperty="Margin" From="10,0,0,0" To="-10,0,0,0" Duration="0:0:2.000" RepeatBehavior="Forever" AutoReverse="True" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <RemoveStoryboard BeginStoryboardName="PlayingStoryboard" />
                        </DataTrigger.ExitActions>
                        <DataTrigger.Setters>
                            <Setter TargetName="ItemBorder" Property="TextElement.FontWeight" Value="Bold" />
                        </DataTrigger.Setters>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=IsNew}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="ItemGridTranslate" Storyboard.TargetProperty="X" From="250" To="0" Duration="0:0:1.000" >
                                        <DoubleAnimation.EasingFunction>
                                            <BackEase />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>

            <DataTemplate x:Key="PlaylistItemMultipleTemplate">
                <Border x:Name="ItemBorder" BorderThickness="1" BorderBrush="Transparent" CornerRadius="2" Padding="0,2,0,2" TextElement.Foreground="{DynamicResource DefaultForeground}">
                    <Grid Name="ItemGridSelected">
                        <Grid.RenderTransform>
                            <TranslateTransform x:Name="ItemGridTranslate"  />
                        </Grid.RenderTransform>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <DockPanel Grid.Column="0" >
                            <Image Grid.Column="1" Width="16" Height="16" Source="/Big3.Hitbase.SharedResources;component/Images/PlaylistError.png"
                                   Visibility="{Binding HasError, Converter={StaticResource BooleanToVisibilityConverter}}" 
                                   ToolTip="{Binding ErrorMessage}" />
                            <Image DockPanel.Dock="Left" Margin="0,0,4,0" Stretch="Uniform" Width="40" Height="40">
                                <Image.Source>
                                    <PriorityBinding>
                                        <Binding Path="TrackImage" IsAsync="True" />
                                        <Binding Path="DefaultTrackImage" IsAsync="False" />
                                    </PriorityBinding>
                                </Image.Source>
                                <Image.Effect>
                                    <DropShadowEffect Color="Gray" ShadowDepth="2" />
                                </Image.Effect>
                            </Image>
                            <StackPanel Orientation="Vertical">
                                <TextBlock Text="{Binding Path=Info.Title}" TextTrimming="CharacterEllipsis" ></TextBlock>
                                <TextBlock Foreground="Gray" Text="{Binding Path=Info.Artist}" TextTrimming="CharacterEllipsis" ></TextBlock>
                            </StackPanel>
                        </DockPanel>
                        <TextBlock Grid.Column="1" Text="{Binding Path=Info.Length, Converter={StaticResource LengthConverter}}" />
                    </Grid>
                </Border>
                <DataTemplate.Triggers>
                    <Trigger SourceName="ItemBorder" Property="IsMouseOver" Value="True">
                        <Setter TargetName="ItemBorder" Property="Background" Value="{DynamicResource MyListBoxItemHoverBackgroundBrush}" />
                        <Setter TargetName="ItemBorder" Property="BorderBrush" Value="#300000FF" />
                    </Trigger>
                    <DataTrigger Binding="{Binding Path=IsPlaying}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard  Name="PlayingStoryboard">
                                <Storyboard>
                                    <ThicknessAnimation Storyboard.TargetName="ItemGridSelected" Storyboard.TargetProperty="Margin" From="10,0,0,0" To="-10,0,0,0" Duration="0:0:2.000" RepeatBehavior="Forever" AutoReverse="True" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <RemoveStoryboard BeginStoryboardName="PlayingStoryboard" />
                        </DataTrigger.ExitActions>
                        <DataTrigger.Setters>
                            <Setter TargetName="ItemBorder" Property="TextElement.FontWeight" Value="Bold" />
                        </DataTrigger.Setters>
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Path=IsNew}" Value="True">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="ItemGridTranslate" Storyboard.TargetProperty="X" From="250" To="0" Duration="0:0:1.000" >
                                        <DoubleAnimation.EasingFunction>
                                            <BackEase />
                                        </DoubleAnimation.EasingFunction>
                                    </DoubleAnimation>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                    </DataTrigger>
                </DataTemplate.Triggers>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="100" />
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <transc:TransitionElement x:Name="TrackDetailTransitionBox" Grid.Row="0">
            <transc:TransitionElement.Transition>
                <transt:FadeAndBlurTransition/>
            </transc:TransitionElement.Transition>
        </transc:TransitionElement>
        <my:TrackDetailViewUserControl Width="150" Opacity="0.8" Background="#20000000" x:Name="NextTrackDetailUserControl" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,3,8" Visibility="Collapsed">
            <my:TrackDetailViewUserControl.LayoutTransform>
                <ScaleTransform ScaleX="0.7" ScaleY="0.6" />
            </my:TrackDetailViewUserControl.LayoutTransform>
        </my:TrackDetailViewUserControl>
        <Rectangle VerticalAlignment="Bottom" Height="5" Grid.Row="0">
            <Rectangle.Fill>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStopCollection>
                        <GradientStop Color="#20000000" Offset="0" />
                        <GradientStop Color="#00000000" Offset="1" />
                    </GradientStopCollection>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>

        <DockPanel Grid.Row="1">
            <!-- Name der Wiedergabeliste -->
            <Grid DockPanel.Dock="Right">
                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">

                    <Button Margin="0,0,5,0" ToolTip="{sr:Loc NewPlaylist}" Command="sr:HitbaseCommands.NewPlaylist">
                        <Image Source="/Big3.Hitbase.SharedResources;component/Images/NewPlaylist.png" Stretch="None" />
                    </Button>
                    <controls:SplitButton Grid.Row="1" HorizontalAlignment="Right" Name="splitButtonView" VerticalAlignment="Top" Height="22"
                                          Image="pack://application:,,,/Big3.Hitbase.SharedResources;component/Images/View.png"
                                          Style="{StaticResource ToolBarSplitButtonStyle}" Click="splitButtonView_Click">
                        <controls:SplitButton.DropDownContextMenu>
                            <ContextMenu>
                                <MenuItem Header="Kachel (erweitert)" Name="MenuItemExtendedView" Click="MenuItemExtendedView_Click" />
                                <MenuItem Header="Details" Name="MenuItemDetails" Click="MenuItemDetails_Click"  />
                            </ContextMenu>
                        </controls:SplitButton.DropDownContextMenu>
                    </controls:SplitButton>
                </StackPanel>
            </Grid>
            <Grid>
                <TextBlock Visibility="{Binding Playlist.IsCDInPlaylist, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false}"  
                           Text="{Binding Path=CDPlaylistTitle}" Name="PlayListCDNameTextBlock" Margin="0,5,10,5"
                           FontStyle="Italic" MouseLeftButtonDown="PlayListNameTextBlock_MouseLeftButtonDown" />

                <TextBlock Visibility="{Binding Playlist.IsCDInPlaylist, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=true}"
                    Text="{Binding Path=Playlist.Name, ElementName=PlaylistUserControl}" Name="PlayListNameTextBlock" Margin="0,5,10,5" FontStyle="Italic" MouseLeftButtonDown="PlayListNameTextBlock_MouseLeftButtonDown" />
                <TextBox Name="TextBoxPlaylistName" Margin="0,0,10,0" Visibility="Collapsed" LostFocus="TextBoxPlaylistName_LostFocus" KeyDown="TextBoxPlaylistName_KeyDown" 
                         />
            </Grid>
        </DockPanel>
        <ListBox AllowDrop="True" SelectionMode="Extended" Grid.Row="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                 HorizontalContentAlignment="Stretch" Name="listBoxPlaylist" BorderThickness="0" ItemContainerStyle="{DynamicResource MyListBoxItemContainerStyle}" 
                 ItemTemplate="{StaticResource PlaylistItemSingleTemplate}" Background="Transparent" 
                 ItemsSource="{Binding ElementName=PlaylistUserControl, Path=Playlist}" MouseDoubleClick="listBoxPlaylist_MouseDoubleClick" 
                 dd:DragDrop.IsDragSource="true" dd:DragDrop.IsDropTarget="true" dd:DragDrop.DragAdornerTemplate="{StaticResource PlaylistItemSingleTemplate}" dd:DragDrop.DropHandler="{Binding}" >
            <ListBox.CommandBindings>
                <CommandBinding Command="sr:HitbaseCommands.DeletePlaylistItem" Executed="CommandBindingDeletePlaylistItem_Executed" CanExecute="CommandBindingDeletePlaylistItem_CanExecute" />
                <CommandBinding Command="sr:HitbaseCommands.SavePlaylist" Executed="CommandBindingSavePlaylist_Executed" CanExecute="CommandBindingSavePlaylist_CanExecute" />
                <CommandBinding Command="sr:HitbaseCommands.OpenTrackLocation" Executed="CommandBindingOpenTrackLocation_Executed" CanExecute="CommandBindingOpenTrackLocation_CanExecute" />
            </ListBox.CommandBindings>
            <ListBox.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Wiedergabeliste speichern" Command="sr:HitbaseCommands.SavePlaylist">
                        <MenuItem.Icon>
                            <Image Source="/Big3.Hitbase.SharedResources;component/Images/Save.png" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Aus Wiedergabeliste entfernen" Command="sr:HitbaseCommands.DeletePlaylistItem">
                        <MenuItem.Icon>
                            <Image Source="/Big3.Hitbase.SharedResources;component/Images/Delete.png" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Header="Speicherort öffnen" Command="sr:HitbaseCommands.OpenTrackLocation">
                        <MenuItem.Icon>
                            <Image Source="/Big3.Hitbase.SharedResources;component/Images/OpenFolder.png" />
                        </MenuItem.Icon>
                    </MenuItem>
                </ContextMenu>
            </ListBox.ContextMenu>
        </ListBox>
        <!--<ListBox Grid.Row="2" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch" Name="listBoxPlaylist" BorderThickness="0" Background="Transparent" ItemsSource="{Binding ElementName=PlaylistUserControl, Path=Playlist}" MouseDoubleClick="listBoxPlaylist_MouseDoubleClick" KeyDown="listBoxPlaylist_KeyDown">
        </ListBox>-->
        <Grid Grid.Row="3">
            <Grid.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStopCollection>
                        <GradientStop Offset="0" Color="#66ffffff" />
                        <GradientStop Offset="1" Color="#00ffffff" />
                    </GradientStopCollection>
                </LinearGradientBrush>
            </Grid.Background>
            <DockPanel >
                <TextBlock Foreground="#77000000" DockPanel.Dock="Right" Margin="2" Name="TextBlockTotalLength" ToolTip="{sr:Loc TotalPlaytimeRemaining}"></TextBlock>
                <TextBlock Foreground="#77000000" Name="TextBlockNumberOfItems" Margin="2,2,5,2" TextTrimming="CharacterEllipsis"></TextBlock>
            </DockPanel>
        </Grid>
    </Grid>
</UserControl>
